'''
Descripttion: 模型函数，存放数据库模型
version: python 3.6.2
Author: 刘涛
Date: 2021-04-14 19:29:01
LastEditors: 刘涛
LastEditTime: 2021-04-27 22:35:43
'''
from django.db import models
from django.contrib.auth.models import User

from datetime import date
from django.urls import reverse
# Create your models here.


class WeChatUser(models.Model):
    # user,级联，用的django里有的user对象
    user = models.OneToOneField(User, models.CASCADE)
    motto = models.CharField(max_length=100, null=True, blank=True)
    region = models.CharField(max_length=50, null=True, blank=True)
    pic = models.CharField(max_length=60, null=True, blank=True)

    def __str__(self):
        return self.user.username


class Status(models.Model):
    user = models.ForeignKey(WeChatUser, models.CASCADE)
    # motto
    text = models.CharField(max_length=280)
    # pic
    pics = models.CharField(max_length=100, null=True, blank=True)
    # region
    pub_time = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.text

    # 以id方式排序，逆序去排
    class Meta:
        ordering = ['-id']


class Reply(models.Model):
    status = models.ForeignKey(Status, models.CASCADE)
    author = models.CharField(max_length=100)
    type = models.CharField(max_length=20, choices=[("0", "like"), ("1", "comment")])
    text = models.CharField(max_length=280, null=True, blank=True)
    at_person = models.CharField(max_length=50, null=True, blank=True)

    def __str__(self):
        return "{} on {}".format(self.author, self.status.text)


class IMG(models.Model):
    # user = models.ForeignKey(WeChatUser, models.CASCADE)
    img = models.ImageField(upload_to='image')
    name = models.CharField(max_length=20)
    # money = models.CharField(max_length=20)

    def __str__(self):  # 在Python3中使用 def __str__(self):
        return self.name

    # # 以id方式排序，逆序去排
    # class Meta:
    #     ordering = ['-id']
